#pragma once
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>		
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/format.hpp>
#include <string>

class CLock
{
private:
	std::mutex mux;
public:
	CLock() {}

	~CLock() {}

	void Lock()
	{
		mux.lock();
	}

	void Unlock()
	{
		mux.unlock();
	}
};

class CConfigIni
{
public:
	~CConfigIni();
private:
	CConfigIni();
	CConfigIni(const CConfigIni&);
	CConfigIni& operator=(const CConfigIni&);

	static std::shared_ptr<CConfigIni> m_pInstance;
	static CLock m_lock;

public:
	static std::string APP_PATH;
	std::string errMsg;

public:	//数据库连接参数
	std::string dbHost;
	std::string dbUser;
	std::string dbPwd;
	std::string dbSchema;
	unsigned int dbPort;

	//tcp服务器端口号
	unsigned int tcpPort;

public:

	//获取句柄
	static std::shared_ptr<CConfigIni> getInstance()
	{
		if (nullptr == m_pInstance)
		{
			m_lock.Lock();
			if (nullptr == m_pInstance)
			{
				m_pInstance = std::shared_ptr<CConfigIni>(new CConfigIni);
			}
			m_lock.Unlock();
		}

		return m_pInstance;
	}

	bool LoadConfigIni(std::string ini_path);

	bool SaveConfigIni(std::string ini_path);

	//获取错误信息
	std::string GetErrMsg(void) { return errMsg; }
};

#define G_INIFILE CConfigIni::getInstance()